﻿using System;
using System.Net;
using GameFramework.Network;
using Pitaya;
using Pitaya.SimpleJson;
using UnityGameFramework.Runtime;
using XLua;

namespace StarForce
{
    [LuaCallCSharp]
    public static class LuaNetWorkUtil
    {
        
        public static INetworkChannel networkChannel;
        public static  NetWorkHelp help;

        public static PomeloClient m_PomeloClient;
        public static void Connect(string ipadress,int port,string handshakeOpts)
        {
             
             help = new NetWorkHelp();
             networkChannel = GameEntry.Network.CreateNetworkChannel("Gate",ServiceType.Tcp, help);
             IPAddress ip;
             if (IPAddress.TryParse(ipadress,out ip))
             {
                 networkChannel.Connect(ip,port);
             }


             help.On("onBroadcast", data =>
             {
                 Log.Debug($"onBroadcast收到回调={data.ToString()}");
             });
             help.On("onCoinChange", data =>
             {
                 Log.Debug($"onCoinChange收到回调={data.ToString()}");
             });
        }

        public static void Request(string route, string msg)
        {
            help.Request(route,msg, data =>
            {
                Log.Debug($"收到回调={data.ToString()}");
            });
            
        }

    }
}